package com.kehutong.help.admin;

import com.kehutong.help.entity.HelpClassify;
import com.kehutong.help.service.HelpClassifyService;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.orm.jdbc.JdbcSession;

import com.kehutong.common.util.Token;

/**
 * 管理后台-消息管理-分类管理
 */
@MvcAction
@ReqMapping("/admin/crm/help/classify")
public class ClassifyController {

    @Inject
    private HelpClassifyService classifyService;
    @Inject
    private JdbcSession jdbcSession;

    // @HasPermission("crm:help:view")
    @ReqMapping("/list/page")
    public Object listPage(JSONObject jsonObject) {
        return classifyService.listPage(jsonObject);
    }

    @ReqMapping("/list")
    public Object list(JSONObject jsonObject) {
        return classifyService.list(jsonObject);
    }

    @Bean(newInstance=true, copy=true)
    // @HasPermission("crm:help:classify:edit")
    @ReqMapping("/save")
    public Object save(HelpClassify classify, Token token) {
        classify.setCreateUserId(token.getUuid());
        classify.setCreateUserName(token.getUsername());

        return classifyService.save(classify);
    }

    @Bean(copy=true)
    // @HasPermission("crm:help:classify:edit")
    @ReqMapping("/update")
    public Object update(HelpClassify classify) {

        return classifyService.update(classify);
    }

    // @HasPermission("crm:help:classify:edit")
    @ReqMapping("/delete")
    public Object delete(HelpClassify classify) {

        return classifyService.delete(classify);
    }

    @ReqMapping("/setEnable")
    public Object setEnable(HelpClassify classify) {
        classify.setEnable(!classify.isEnable());
        classifyService.update(classify);
        return Result.success();
    }

    @Bean(copy = true)
    // @HasPermission("crm:help:classify:edit")
    @ReqMapping("/updateSort")
    public Object updateSort(HelpClassify classify, Integer sort) {

        return classifyService.updateSort(classify, sort);
    }

    @ReqMapping("/get")
    public Object get(HelpClassify classify) {

        return Result.success(classify);
    }
}
